import { NLog } from "naive-ui";
import type { LogProps, LogInst } from "naive-ui";
import type { HTMLAttributes } from "vue";
export type LogFactoryConstructorType = {
  props?: LogProps;
  attrs?: HTMLAttributes;
};
export class LogFactory {
  private props: LogProps = {};
  private attrs: HTMLAttributes = {};
  private domRef: LogInst | null = null;
  constructor(data?: LogFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
  }

  setProps(props: LogProps) {
    this.props = props;
    return this;
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }

  scrollTo(options: { silent?: boolean; position: "top" | "bottom" }) {
    this.domRef?.scrollTo(options);
  }
  create() {
    return (
      <NLog
        ref={(el: HTMLElement) => {
          this.domRef = el as unknown as LogInst;
        }}
        {...this.attrs}
        {...this.props}
      ></NLog>
    );
  }
}
